<template>
    <div>
        <template v-for="item in treeData">
            <el-sub-menu
                :index="item._id"
                v-if="item.children && item.children.length > 0 "
            >
                <template #title>
                    <el-icon>
                        <component :is="item.icon"></component>    
                    </el-icon>
                    <span>{{ item.menuName }}</span>
                </template>
                <TreeMenu :treeData="item.children"></TreeMenu>
            </el-sub-menu>
            <el-menu-item
                v-else-if="item.menuType === 1"
                :index = "item.path"
                :key="item._id"
            >
                <el-icon :size="20">
                    <component :is="item.icon"></component>    
                </el-icon>
                {{ item.menuName }}
            </el-menu-item>
        </template>
    </div>
</template>

<script>
export default{
    name: "TreeMenu",
    props:{
        treeData:{
            type: Array,
            default: function(){
                return []
            }
        }
    }
}
</script>

<style scoped>
    .el-icon{
        color: gray;
    }
</style>